<?php
 
  class Config_m extends CI_Model
  {
      
      function __construct()
      {
         parent::__construct();
         $this->load->database();
     }
        
     function insert($arr)
     {
        $this->db->insert('config',$arr);
        return $this->db->insert_id();
     }  
     
     function update($where,$arr)
     {  
         $this->db->where($where);
         $this->db->update('config',$arr);
     }
            
     function delete($where)
     {
         $this->db->where($where);
         $this->db->delete('config');
     }
     
     //查询获取单条
     function get_one($where,$select='*'){
        $this->db->select($select);
        if($where){
            $this->db->where($where);
        }
        $this->db->limit(1);
        $query = $this->db->get('config');
        return $query->row_array();
    }

     //正序 全查         
     function select($where='',$order_by='',$limit='')
     {  
         // where 条件
         if($where){
          $this->db->where($where);  
         }
         
         // order_by 条件
         if($order_by){
          $this->db->order_by($order_by);
         }
         // limit 条件
         if($limit){
          $this->db->limit($limit);
         }
         
         $this->db->select('*');
         $data = $this->db->get('config');
         return  $data->result_array();
     }

     //正序 全查         
     function getconfig($where='')
     {  
         // where 条件
         if($where){
          $this->db->where($where);  
         }
         
         $this->db->select('name,value');
         $data = $this->db->get('config');         
         $data=$data->result_array();
         $result=array();
         if($data){
            foreach ($data as $key => $value) {
                $result[$value['name']]=$value['value'];
            }
         }
         return $result;
     }
     
 }
 ?>